<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>组件通信-父传子 - {{count}}</h2>
      <button @click="count++">btn</button>
      <child abc="hello" :count="count"></child>
    </div>

    <script src="./Vue3.js"></script>
    <script>
      // 默认情况下，组件之间的数据和方法都是不共享的，每一个组件都要去维护自己的数据和方法

      // 父传子
      // 1. 在父组件的子组件标签上面，添加一个自定义属性(传递)
      // 2. 在子组件里面使用props选项进行接收
      const { createApp } = Vue;

      const Sun = {
        props: ["count", "name"],
        template: `
          <div>这是孙组件 - {{ count }} - {{ name }}</div>
        `,
      };

      const Child = {
        props: ["abc", "count"],
        data() {
          return {
            list: ["zhangsan", "lisi", "wangwu"],
          };
        },
        template: `
          <div>这是子组件 - {{ abc }} - {{ count }}</div>
          <sun :count="count" v-for="item in list" :key="item" :name="item"></sun>
        `,
        components: {
          Sun,
        },
      };

      createApp({
        data() {
          return {
            count: 10,
          };
        },
        components: {
          Child,
        },
      }).mount("#app");
    </script>
  </body>
</html>
